﻿
Option Explicit On

Namespace Blog

    <CLSCompliant(True)> _
    Public Class Comment

        Inherits BlogSpark.Common.ObjectBase

#Region "Members"

        Private _CommentId As Integer = 0
        Private _PostId As Integer
        Private _Parent As Integer
        Private _byUserId As Integer
        Private _Body As String = String.Empty
        Private _Created As DateTime
        Private _isReviewed As Boolean

#End Region

#Region "Constructors"

        Public Sub New()
        End Sub

#End Region

#Region "Methods"

        Public Overrides Sub Fill(ByVal dr As DataRow)

            _CommentId = dr(enumCommentFields.CommentID)
            PostID = dr(enumCommentFields.PostID)
            Parent = dr(enumCommentFields.Parent)
            ByUserID = dr(enumCommentFields.ByUserID)
            Body = dr(enumCommentFields.Body)
            Created = dr(enumCommentFields.Created)
            IsReviewed = dr(enumCommentFields.isReviewed)

        End Sub

        Public Sub Save()

            If _CommentId = 0 Then
                _CommentId = BlogSpark.DataProvider.SPs.InsertComment(BlogSpark.DataProvider.Data.ConnectionType, PostID, Parent, ByUserID, Body, IsReviewed)
            Else
                BlogSpark.DataProvider.SPs.UpdateComment(BlogSpark.DataProvider.Data.ConnectionType, CommentID, PostID, Parent, ByUserID, Body, Created, IsReviewed)
            End If

        End Sub

        Public Sub Delete()

            BlogSpark.DataProvider.SPs.DeleteComment(BlogSpark.DataProvider.Data.ConnectionType, CommentID)

        End Sub

#End Region

#Region "Properties"

        Public ReadOnly Property CommentID() As Integer
            Get
                Return _CommentId
            End Get
        End Property

        Public Property PostID() As Integer
            Get
                Return _PostId
            End Get
            Set(ByVal value As Integer)
                _PostId = value
            End Set
        End Property

        Public Property Parent() As Integer
            Get
                Return _Parent
            End Get
            Set(ByVal value As Integer)
                _Parent = value
            End Set
        End Property

        Public Property ByUserID() As Integer
            Get
                Return _byUserId
            End Get
            Set(ByVal value As Integer)
                _byUserId = value
            End Set
        End Property

        'TODO: Finish This
        'Public ReadOnly Property User() As BlogSpark.Members.User
        '    Get
        '        If _byUserId > 0 Then
        '            'Dim objUser As BlogSpark.Members.User = BlogSpark.Members.UserUtils.
        '        Else
        '            Return Nothing
        '        End If
        '    End Get
        'End Property

        Public Property Body() As String
            Get
                Return _Body
            End Get
            Set(ByVal value As String)
                _Body = value
            End Set
        End Property

        Public Property Created() As DateTime
            Get
                Return _Created
            End Get
            Set(ByVal value As DateTime)
                _Created = value
            End Set
        End Property

        Public Property IsReviewed() As Boolean
            Get
                Return _isReviewed
            End Get
            Set(ByVal value As Boolean)
                _isReviewed = value
            End Set
        End Property

#End Region

#Region "Enum"

        Private Enum enumCommentFields As Byte

            CommentID = 0
            PostID
            Parent
            ByUserID
            Body
            Created
            isReviewed

        End Enum

#End Region

    End Class

End Namespace

